import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '@/views/home/HomeView.vue'
import Layout from '@/views/layout'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    // name: 'Layout',
    component: Layout,
    children: [
      {
        path: '/',
        name: 'home',
        component: HomeView
      },
      {
        path: '/about',
        name: 'about',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
      },
      {
        path: '/travel',
        component: () => import('@/views/travel/index.vue')
      },
      {
        path: '/community',
        name: 'community',
        component: () => import('@/views/community/index.vue')
      },
      {
        path: '/blog/:bid',
        name: 'blog',
        component: () => import('@/views/community/BlogDetail.vue')
      },
      {
        path: '/attraction/:attrId',
        name: 'attraction',
        component: () => import('@/views/travel/Attraction.vue')
      },
      {
        path: '/edit',
        name: 'edit',
        component: () => import('@/views/community/EditBlog.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/user',
        name: 'user',
        component: () => import('@/views/user/index.vue'),
        meta: {
          isLogin: true
        },
        children: [
          {
            path: '/userinfo',
            name: 'userinfo',
            component: () => import('@/components/user/UserInfo.vue')
          },
          {
            path: '/orderInfo',
            name: 'orderInfo',
            component: () => import('@/components/order/OrderInfo.vue')
          },
          {
            path: '/blogInfo',
            name: 'blogInfo',
            component: () => import('@/components/blog/BlogInfo.vue')
          },
        ]
      },
      {
        path: '/order',
        name: 'order',
        component: () => import('@/views/order/index.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/orderSuccess',
        name: 'orderSuccess',
        component: () => import('@/views/order/OrderSuccess.vue')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index.vue')
  }
]

// const router = new VueRouter({
//   mode: 'history',
//   routes
// })

const createRouter = () => new VueRouter({
  mode: 'history', // require service support
  // scrollBehavior: () => ({ y: 0 }),
  routes
  // routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}


export default router
